#include <GL/gl.h>
#include "qzerolayer.h"


QZeroLayer::QZeroLayer()
  : theTex_()
{
  zoom_ = 1.0f;
  angle_ = 0.0f;
  xtrans_ = 0.0f;
  ytrans_ = 0.0f;
}

QZeroLayer::QZeroLayer(const QZeroLayer& layer)
{
  zoom_ = layer.zoom_;
  angle_ = layer.angle_;
  xtrans_ = layer.xtrans_;
  ytrans_ = layer.ytrans_;
  theTex_ = layer.theTex_;
}

void QZeroLayer::draw(unsigned int width, unsigned int height, int z)
{
  int w = width;
  int h = height;
  glDisable(GL_DEPTH_TEST);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0,w,0,h,-1,1);
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  glEnable(GL_TEXTURE_2D);
  theTex_.Bind();

  glTranslatef(xtrans_, ytrans_, 0.0f);
  glRotatef(angle_, 0.0f, 0.0f, 1.0f);
  glScalef(zoom_, zoom_, 1.0f);

  glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0,  z);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(w, 0,  z);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(w, h,  z);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(0, h,  z);
  glEnd();

  glPopMatrix();
  glMatrixMode(GL_PROJECTION);					//Select the projection matrix
  glPopMatrix();									//Restore the old projection matrix
  glMatrixMode(GL_MODELVIEW);						//Select the modelview matrix
  glEnable(GL_DEPTH_TEST);

}
